var express = require('express');
var router = express.Router();
var http = require('http');

/* GET users listing. */
router.get('/:geohash/:offset/:limit', function(req, resp, next) {

    var geohash = req.params.geohash;
    var limit = req.params.limit || 24;
    var offset = req.params.offset || 0;
    var data = "";
    http.get("http://ele.me/restapi/v3/restaurants?type=geohash&offset="+ offset +"&limit="+ limit +"&geohash=" + geohash,function(res){
        res.on("data", function(chunk) {
            console.log(data += chunk);
        });
        res.on('end', function() {
            if (data != '') {
                resp.send(JSON.stringify(data));
            }
            else {
                resp.send(JSON.stringify(data));
            }
        });
    }).on('error',function(e){
        console.log("Got error: " + e.message);
    })


});

module.exports = router;
